

cc.Class({
    extends: cc.Component,

    properties: {
        ed_username:cc.EditBox,
        ed_password:cc.EditBox,
        ed_rePassword:cc.EditBox,
        ed_key:cc.EditBox,
    },

    btn_backClicked(){
        this.node.destroy();
    },

    btn_registClicked(){
        let cur_username = this.getEditBoxValue(this.ed_username);
        let cur_password = this.getEditBoxValue(this.ed_password);
        let cur_rePassword = this.getEditBoxValue(this.ed_rePassword);
        let cur_key = this.getEditBoxValue(this.ed_key);

        if(!cur_username){
            G.showToast('用户名不能为空!');
            return;
        }
        if(!cur_password || !cur_rePassword){
            G.showToast('密码不能为空!');
            return;
        }
        if(cur_rePassword !== cur_password){
            G.showToast('两次密码不一致!');
            return;
        }
        if(!cur_key){
            G.showToast('key不能为空!');
            return;
        }
        G.netApi.user_create({
            username:cur_username,
            password:G.md5(cur_password),
            key:G.md5(cur_key),
        },(err,data)=>{
            if(err){
                G.showToast('注册出现错误!');
            }else{
                if(data.err){
                    G.showToast(data.msg);
                }else{
                    G.showToast('注册成功!');

                    // 回到登陆界面
                    this.node.destroy();
                }
            }
        });
    },

    getEditBoxValue(editbox){
        return editbox.string.trim();
    },
});
